package com.snailct.bpp.service.core.handle;

import com.snailct.bpp.commons.exception.ErrorCode;
import com.snailct.bpp.commons.utils.DBManager;
import com.snailct.bpp.service.core.CoreException;
import com.snailct.bpp.service.core.dao.ServiceDefinitionDao;
import com.snailct.bpp.service.core.definition.DefaultServiceDefinition;
import com.snailct.bpp.service.core.definition.ServiceDefinition;
import com.snailct.bpp.service.core.definition.ServiceMeta;
import com.snailct.bpp.service.core.definition.ServiceType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 服务仓库
 */
@Component
public class ServiceRepository {
    private enum ServiceReposError{
        @ErrorCode(comment = "The args is illegal!")
        DEFINITION_ERROR
    }
    @Autowired
    private ServiceDefinitionDao serviceDefinitionDao;
    public ServiceDefinition getServiceDefinition(ServiceDefinition serviceDefinition){
        DefaultServiceDefinition result = (DefaultServiceDefinition)serviceDefinition;
        try {
            result = serviceDefinitionDao.getServiceDefinitionById(result.getServiceId());
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(!result.validate()){
            throw new CoreException(ServiceReposError.DEFINITION_ERROR);
        }
        return result;
    }
}
